﻿define(['jquery', 'kendo', 'moment', 'ajax-pre'], function ($, kendo, moment) {

    //var departments = JSON.parse(document.getElementById('t').value);

    var dataSource = new kendo.data.DataSource({
        schema: {
            data: function (response) {
                return response;
            },
            total: function (response) {
                return response.Total;
            },
            model: {
                id: "Id",
                fields: {
                    Id: { nullable: false },
                    PostName: { validation: { required: true } },
                    Remark:{}
                }
            }
        },
        pageSize: 12,
        serverPaging: true,
        batch: true,
        transport: {
            read: {
                url: "/PostInfo/Get",
                dataType: "json",
                method: "post"
            },
            update: {
                url: "/PostInfo/Save",
                dataType: "json",
                method: "post",
                contentType: "application/json"
            },
            destroy: {
                url: "/PostInfo/Remove",
                dataType: "json",
                method: "post",
                contentType: "application/json"
            },
            create: {
                url: "/PostInfo/Save",
                dataType: "json",
                method: "post",
                contentType: "application/json"
            },
            parameterMap: function (options, operation) {
                debugger;
                if (operation !== "read" && options.models) {
                    return JSON.stringify({ entitys: options.models });
                }
                if (operation == "read") {
                    return {
                        page: {
                            page: options.page,
                            pages: options.pageSize
                        }
                    };
                }
            }
        }
    });

    $("#grid").kendoGrid({
        dataSource: dataSource,
        filterable: true,
        toolbar: [{ name: "create", text: '新建' }, { name: "save", text: '保存' }],
        pageable: {
            refresh: true,
            pageSizes: true,
            buttonCount: 5
        },
        columns: [
        { field: "PostName", title: "岗位名称", width: '180px' },
        { field: "Remark", title: "备注" },
        {
            width: '250px',
            command: [
              { name: "destroy", 'text': '删除' },
              { name: "edit", text: '编辑' }
            ]
        }
        ],
        editable: { //disables the deletion functionality
            update: true,
            destroy: true,
            create: true,
            mode: 'inline',// inline popup
        },
        //editable: "popup",
        pageable: true,

    });
});